<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Comment_model extends CI_Model { 
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
	
    public function query_get_comment()
    {
        return 
            "select
                comment.id,
                comment.comment_car as comment,
                member.name as member_name,
                member.photo
            from     
                psacar_comment as comment
                inner join psacar_car as car on comment.car_id = car.id
                inner join psacar_member as member on comment.member_id = member.id ";
    }
    
    public function get_comments()
    {               
        $query_string = $this->query_get_comment();        
        
        $result = $this->db->query($query_string);
        return $result;
    }
    
    public function get_comments_by_car($car_id)
    {               
        $query_string = 
            $this->query_get_comment() . 
            "where  
                car.id = " . $car_id;

        $result = $this->db->query($query_string);
        return $result;
    }    
}